/*
 * @Author: your name
 * @Date: 2021-11-25 15:28:41
 * @LastEditTime: 2021-11-25 15:44:39
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \li-yuwei\client\src\utils\getDateDiff.js
 */

function getDateDiff(dateTimeStamp) {
    var result = "";
    var minute = 1000 * 60; //1分钟
    var hour = minute * 60; //1小时
    var day = hour * 24; //1天
    var month = day * 30; //1月
    var year = month * 12; //1年
    var now = new Date().getTime();
    var diffValue = now - dateTimeStamp;
    if (diffValue < 0) return;
    var yearC = diffValue / year;
    var monthC = diffValue / month;
    var weekC = diffValue / (7 * day);
    var dayC = diffValue / day;
    var hourC = diffValue / hour;
    var minC = diffValue / minute;
    if (yearC >= 1) {
        result = "" + parseInt(yearC) + "年前";
    } else if (monthC >= 1) {
        result = "" + parseInt(monthC) + "月前";
    } else if (weekC >= 1) {
        result = "" + parseInt(weekC) + "周前";
    } else if (dayC >= 1) {
        result = "" + parseInt(dayC) + "天前";
    } else if (hourC >= 1) {
        result = "" + parseInt(hourC) + "小时前";
    } else if (minC >= 1) {
        result = "" + parseInt(minC) + "分钟前";
    } else {
        result = "刚刚";
    }
    return result;
}
export default getDateDiff;